package ru.resumeService.service.impl;

import ru.resumeService.service.UserService;
import ru.resumeService.service.db.ConnectionFactory;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;

import static ru.resumeService.service.db.ConnectionFactory.getFactory;

public class UserServiceImpl implements UserService {

    private static ConnectionFactory factory = ConnectionFactory.getFactory();

    @Override
    public boolean isUserValid(String login, String password) {
        String sql = "SELECT * FROM users WHERE login='" + login + "' AND password='" + password + "'";
        ResultSet rs;
        try {
            Connection connection = factory.getConnection();
            rs = connection.createStatement().executeQuery(sql);
            boolean isValid = rs.next();
            connection.close();
            return isValid;
        } catch (SQLException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }
        return false;
    }
}
